package cn.iocoder.yudao.module.erp.dal.mysql.invoicechecklistitem;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.invoicechecklistitem.vo.InvoiceCheckListItemPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.invoicechecklistitem.InvoiceCheckListItemDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * ERP 采购发票审核单项 Mapper
 *
 * @author 源码
 */
@Mapper
public interface InvoiceCheckListItemMapper extends BaseMapperX<InvoiceCheckListItemDO> {

    default PageResult<InvoiceCheckListItemDO> selectPage(InvoiceCheckListItemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InvoiceCheckListItemDO>()
                .eqIfPresent(InvoiceCheckListItemDO::getCheckInvoiceId, reqVO.getCheckInvoiceId())
                .eqIfPresent(InvoiceCheckListItemDO::getNumber, reqVO.getNumber())
                .eqIfPresent(InvoiceCheckListItemDO::getType, reqVO.getType())
                .betweenIfPresent(InvoiceCheckListItemDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InvoiceCheckListItemDO::getId));
    }

    //    根据审核单编号查询采购单编号
    List<Integer> getPurchaseOrderIdByCheckInvoiceId(String checkInvoiceId);

    @Select("SELECT number FROM erp_invoice_check_list_item WHERE check_invoice_id = #{checkInvoiceId}")
    List<Long> getInvoiceByCheckInvoiceId(String checkInvoiceId);

    default List<InvoiceCheckListItemDO> getInvoiceCheckListItemDOByIds(List<String> ids){
        return selectList(InvoiceCheckListItemDO::getNumber,ids);
    }

    default List<InvoiceCheckListItemDO> getInvoiceCheckListItemDOByNumbers(List<String> numbers){
        return selectList(InvoiceCheckListItemDO::getNumber,numbers);
    }

    default List<InvoiceCheckListItemDO> getInvoiceByCheckInvoiceIds(List<String> checkInvoiceIds){
        return selectList(InvoiceCheckListItemDO::getCheckInvoiceId,checkInvoiceIds);
    }
}